package com.example.data

import com.example.data.entity.ASMREntity
import com.example.data.entity.TagEntity
import kotlinx.coroutines.Dispatchers
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
import org.jetbrains.exposed.sql.transactions.transaction

//
//import org.ktorm.database.Database
//
//
object DatabaseFactory {
    fun init() {
        val driverClassName = "com.mysql.cj.jdbc.Driver"
        val jdbcURL = "jdbc:mysql://localhost:3306/fun_acg2"
        val database = Database.connect(jdbcURL, driverClassName, "root", "root")
        transaction(database) {
            SchemaUtils.create(ASMREntity,TagEntity)
        }
    }


}
suspend fun <T> dbQuery(block: suspend () -> T): T =
    newSuspendedTransaction(Dispatchers.IO) { block() }